import { createSlice } from "@reduxjs/toolkit";
import { RootState } from "store";

interface State {
  projectModalOpen: boolean;
  openModelId: number;
  type: string;
}

const initialState: State = {
  projectModalOpen: false,
  openModelId: 0,
  type: "", //model打开的类型
};

export const projectListSlice = createSlice({
  name: "projectListSlice",
  initialState,
  reducers: {
    openProjectModal(state) {
      state.projectModalOpen = true;
    },
    closeProjectModal(state) {
      state.projectModalOpen = false;
    },
    openModelId(state, payload: { payload: { id: number; type: string } }) {
      const { id, type } = payload.payload;
      state.openModelId = id;
      state.type = type;
    },
  },
});
export const projectListAction = projectListSlice.actions;
export const selectprojectModalOpen = (state: RootState) => {
  return state.projectList.projectModalOpen;
};
export const selectprojectopenModelId = (state: RootState) => {
  return {
    openModelId: state.projectList.openModelId,
    type: state.projectList.type,
  };
};
